<?php
function total_rating($incident_id) {
	$initial_rating_query ="SELECT initial_rating from incidents WHERE incident_id = ?";
	$query = "SELECT COUNT(*) as num_ratings from ratings WHERE incident_id = ?";
	$initial_rating = query($initial_rating_query, array($incident_id));
	$count = query($query, array($incident_id));
	return $initial_rating[0]['initial_rating'] + $count[0]['num_ratings'];
}
function set_total_rating ($incidents){
	$modified_incidents = array();
	foreach ($incidents as $incident) {
		$modified_incident = $incident;
		$modified_incident['rating'] = total_rating($incident["incident_id"]);
		$modified_incidents[] = $modified_incident;
	}
	return $modified_incidents;
}